import logging
from datetime import timedelta
from redis import StrictRedis


class Config:
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/info14"
    SQLALCHEMY_TRACK_MODIFICATIONS = True
    SECRET_KEY = "osUskNrvhadLAHWTOrWEhBmwzweuG9vhitwSUqYuLWTYJ4xQMt/mgFiN3W5b5CFL"  # 设置app秘钥
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    SESSION_TYPE = "redis"  # 使用redis来存储会话,效率高
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)  # 指定自定义的redis管理器
    SESSION_USE_SIGNER = True  # 是否对cookie发过来的sessionid加密 需要设置app秘钥
    PERMANENT_SESSION_LIFETIME = timedelta(days=7)  # 设置过期时间
    WTF_CSRF_ENABLED = False  # 先取消csrf认证


class DevelopmentConfig(Config):  # 开发环境配置
    DEBUG = True
    LOG_LEVEL = logging.DEBUG  # 设置日志级别


class ProductConfig(Config):  # 生产环境配置
    DEBUG = False
    LOG_LEVEL = logging.ERROR  # 设置日志级别


class UnitTestConfig(Config):  # 单元测试配置
    DEBUG = True
    TESTING = True
    LOG_LEVEL = logging.DEBUG  # 设置日志级别


# 定义字典记录配置类
config = {"dev": DevelopmentConfig,
          "pro": ProductConfig,
          "test": UnitTestConfig}
